package com.kimehwa.studyboot.mainTestThread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;


public class FutureTaskTest {
    public static final int MAX_TURN = 5;
    public static final int COMPUTE_TIMES =100000000;

    static class ReturnableTask implements Callable<Long>{

        @Override
        public Long call() throws Exception {
            long startTime = System.currentTimeMillis();
            System.out.println("-------");
            Thread.sleep(1000);
            for(int i = 0;i<COMPUTE_TIMES;i++){
                int j = i*10000;
            }
            long used = 1000;
            return used;
        }
    }

    public static void main(String[] args) throws InterruptedException, ExecutionException {
        ReturnableTask task = new ReturnableTask();
        FutureTask<Long> futureTask = new FutureTask<Long>(task);
        Thread thread = new Thread(futureTask, "returnableThread");
        thread.start();
        Thread.sleep(500);
        System.out.println("让子弹飞一会儿");
        System.out.println(new StringBuilder().append("返回结果").append(futureTask.get()).toString());


    }
}
